<?php

namespace app\frontend;

use app\controller\BaseController;
use app\general\utils\ConversionUtils;
use Carbon\Carbon;
use support\Db;
use support\Request;



class IndexController extends BaseController
{

    public function index(Request $request)
    {
        $WebUsers = Db::table('movie_basic')
            ->when(is_numeric($request->input('status')) , function ($query) use ($request) {
                return $query->where('status', $request->input('status'));
            })->when($request->input('type'), function ($query) use ($request) {
                return $query->where('type', $request->input('type'));
            })
            ->paginate($request->get('pageSize',10));
        $items = $WebUsers->items();
        foreach ($items as $key=>$val){
            $items[$key] = ConversionUtils::underscoreToHump($val) ;
            $items[$key]['createTime'] = Carbon::parse($items[$key]['createTime'])->toIso8601String();
            $items[$key]['casts'] = [];
            $items[$key]['country'] = [];
            $items[$key]['moviePv'] = [];
            $items[$key]['movieRate'] = ['rate'=>8];
        }
       return json($this->successFrontData('',[['name'=>'aaa','type'=>1,'rows'=>$items,'ranks'=>$items,'genres'=>$items]],$WebUsers->total()));
    }

    public function view(Request $request)
    {
        return view('index/view', ['name' => 'webman']);
    }

    public function json(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }

}
